import 'package:flutter/material.dart';
import 'package:test1/bean/ItemInfo.dart';
import 'package:test1/listitems/HomeListItem.dart';
import 'package:test1/View/TextWdigetPage.dart';

class ListView_Separated_Page extends StatelessWidget {
  var list = [
    ItemInfo("ListView的一行数据"),
    ItemInfo("ListView的一行数据"),
    ItemInfo("ListView的一行数据"),
    ItemInfo("ListView的一行数据")
  ];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text(
              "ListView的separated方式"
          ),
        ),
        //多了separatorBuilder 可以直接设置分割线
        body: ListView.separated(
          itemBuilder: (context, position) {
            return HomeListItem(position, list[position], (index) =>
                Navigator.push(
                    context,
                    new MaterialPageRoute(builder: (BuildContext context) {
                      return TextWdigetPage();
                    })
                )
            );
          },
          // 添加分割线,
          separatorBuilder: (BuildContext context, int index) => new Divider(),
          itemCount: list.length,
        ),
      ),
    );
  }
}